//
//  YQWebManager.m
//  iyuanqi
//
//  Created by czl on 2017/7/27.
//  Copyright © 2017年 czl. All rights reserved.
//

#import "YQWebManager.h"

@implementation YQWebManager

NSString  *const service = @"http://www.xmyuanqi.cn/plugin.php";


//登录
+ (void)loginIn:(NSString*)username password:(NSString*)password withSuccessBlock:(BAResponseSuccess)successBlock withFailureBlock:(BAResponseFail)failureBlock {
    [BANetManager ba_request_POSTWithUrlString:service isNeedCache:NO parameters:@{@"id":@"xiaoya_appjson",@"func":@"user_login",@"username":username,@"password":password} successBlock:successBlock failureBlock:failureBlock progress:nil];
}

#pragma mark 注册
+ (void)registerUser:(NSString*)username password:(NSString*)password email:(NSString*)email withSuccessBlock:(BAResponseSuccess)successBlock withFailureBlock:(BAResponseFail)failureBlock {
    [BANetManager ba_request_POSTWithUrlString:service isNeedCache:NO parameters:@{@"id":@"xiaoya_appjson",@"func":@"user_register",@"username":username,@"password":password,@"email":email} successBlock:successBlock failureBlock:failureBlock progress:nil];
}

#pragma mark 获取用户信息
+ (void)getUserInfo:(NSString*)uid withSuccessBlock:(BAResponseSuccess)successBlock withFailureBlock:(BAResponseFail)failureBlock {
    [BANetManager ba_request_GETWithUrlString:service isNeedCache:NO parameters:@{@"id":@"xiaoya_appjson",@"func":@"xiaoya_user_set",@"uid":uid} successBlock:successBlock failureBlock:failureBlock progress:nil];
}

+ (void)getBanners:(BAResponseSuccess)successBlock withFailureBlock:(BAResponseFail)failureBlock {
    [BANetManager ba_request_GETWithUrlString:service isNeedCache:NO parameters:@{@"id":@"xiaoya_appjson",@"func":@"get_banner_recycle"} successBlock:successBlock failureBlock:failureBlock progress:nil];
}


+ (void)getForumList:(BAResponseSuccess)successBlock withFailureBlock:(BAResponseFail)failureBlock {
    [BANetManager ba_request_GETWithUrlString:service isNeedCache:NO parameters:@{@"id":@"xiaoya_appjson",@"func":@"get_forum_forum"} successBlock:successBlock failureBlock:failureBlock progress:nil];
}

//获取帖子列表
+ (void)getArticleList:(NSString*)fid type:(NSInteger)type page_l:(NSInteger)page_l page_r:(NSInteger)page_r withSuccessBlock:(BAResponseSuccess)successBlock withFailureBlock:(BAResponseFail)failureBlock {
    [BANetManager ba_request_GETWithUrlString:service isNeedCache:NO parameters:@{@"id":@"xiaoya_appjson",@"func":@"get_forum_post",@"fid":fid,@"type":@(type),@"page_l":@(page_l),@"page_r":@(page_r)} successBlock:successBlock failureBlock:failureBlock progress:nil];
}

#pragma mark 获取单条帖子
+ (void)getArticleDetail:(NSString*)tid withSuccessBlock:(BAResponseSuccess)successBlock withFailureBlock:(BAResponseFail)failureBlock {
    [BANetManager ba_request_GETWithUrlString:service isNeedCache:NO parameters:@{@"id":@"xiaoya_appjson",@"func":@"get_forum_post_a",@"tid":tid,@"uid":[YQSingletonManager getInstance].userObject.uid.length>0?[YQSingletonManager getInstance].userObject.uid:@""} successBlock:successBlock failureBlock:failureBlock progress:nil];
}

#pragma mark 获取评论
+ (void)getReplys:(NSString*)tid withSuccessBlock:(BAResponseSuccess)successBlock withFailureBlock:(BAResponseFail)failureBlock {
    [BANetManager ba_request_GETWithUrlString:service isNeedCache:NO parameters:@{@"id":@"xiaoya_appjson",@"func":@"get_first_comment",@"tid":tid,@"uid":[YQSingletonManager getInstance].userObject.uid.length>0?[YQSingletonManager getInstance].userObject.uid:@""} successBlock:successBlock failureBlock:failureBlock progress:nil];
}

#pragma mark 发表主题
+ (void)postTopic:(NSString*)fid subject:(NSString*)subject message:(NSString*)message imageArray:(NSArray<UIImage*>*)imageArray withSuccessBlock:(BAResponseSuccess)successBlock withFailureBlock:(BAResponseFail)failureBlock {
    [BANetManager ba_uploadImageWithUrlString:service parameters:@{@"id":@"xiaoya_appjson",@"func":@"newthread",@"uid":[YQSingletonManager getInstance].userObject.uid.length>0?[YQSingletonManager getInstance].userObject.uid:@"",@"username":[YQSingletonManager getInstance].userObject.username.length>0?[YQSingletonManager getInstance].userObject.username:@"",@"subject":subject,@"message":message} imageArray:imageArray fileNames:nil imageType:nil imageScale:1 successBlock:successBlock failurBlock:failureBlock uploadProgress:nil];
}

#pragma mark 回复主题
+ (void)postReply:(NSString*)tid message:(NSString*)message imageArray:(NSArray<UIImage*>*)imageArray withSuccessBlock:(BAResponseSuccess)successBlock withFailureBlock:(BAResponseFail)failureBlock {
    [BANetManager ba_uploadImageWithUrlString:service parameters:@{@"id":@"xiaoya_appjson",@"func":@"newpost",@"uid":[YQSingletonManager getInstance].userObject.uid.length>0?[YQSingletonManager getInstance].userObject.uid:@"",@"fid":@"",@"tid":tid,@"subject":@"",@"message":message} imageArray:imageArray fileNames:nil imageType:nil imageScale:1 successBlock:successBlock failurBlock:failureBlock uploadProgress:nil];
}

#pragma mark 收藏文章
+ (void)collectarticle:(NSString*)tid withSuccessBlock:(BAResponseSuccess)successBlock withFailureBlock:(BAResponseFail)failureBlock {
    [BANetManager ba_request_GETWithUrlString:service isNeedCache:NO parameters:@{@"id":@"xiaoya_appjson",@"func":@"newcollection",@"idtype":tid,@"uid":[YQSingletonManager getInstance].userObject.uid.length>0?[YQSingletonManager getInstance].userObject.uid:@"",@"tid":tid} successBlock:successBlock failureBlock:failureBlock progress:nil];
}

#pragma mark 获取某人发表的文章
+ (void)getUserPostArticles:(NSString*)uid page_l:(int)page_l withSuccessBlock:(BAResponseSuccess)successBlock withFailureBlock:(BAResponseFail)failureBlock {
    [BANetManager ba_request_GETWithUrlString:service isNeedCache:NO parameters:@{@"id":@"xiaoya_appjson",@"func":@"newcollection",@"uid":uid,@"page_l":@(page_l),@"page_r":@(20)} successBlock:successBlock failureBlock:failureBlock progress:nil];
}

#pragma mark 获取某人收藏的文章
+ (void)getUserCollectArticles:(NSString*)uid page_l:(int)page_l withSuccessBlock:(BAResponseSuccess)successBlock withFailureBlock:(BAResponseFail)failureBlock {
    [BANetManager ba_request_GETWithUrlString:service isNeedCache:NO parameters:@{@"id":@"xiaoya_appjson",@"func":@"get_collection",@"uid":uid,@"page_l":@(page_l),@"page_r":@(20)} successBlock:successBlock failureBlock:failureBlock progress:nil];
}

@end
